package com.hzcx.app.simplechat.ui.mine;

import android.os.Bundle;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseActivity;
import com.hzcx.app.simplechat.bean.UpLoadImgBean;
import com.hzcx.app.simplechat.event.EditUserInfoEvent;
import com.hzcx.app.simplechat.ui.mine.contract.EditUserInfoContract;
import com.hzcx.app.simplechat.ui.mine.presenter.EditUserInfoPresenter;
import com.hzcx.app.simplechat.ui.user.bean.CityListBean;
import com.hzcx.app.simplechat.ui.user.bean.UserInfoBean;
import com.hzcx.app.simplechat.util.UserInfoUtil;
import com.hzcx.app.simplechat.view.MainBlueConfirmButton;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 修改用户ID
 */
public class EditUserIdActivity extends BaseActivity<EditUserInfoPresenter> implements EditUserInfoContract.View {

    public static final String INTENT_EDIT_USERID = "INTENT_EDIT_USERID";

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.iv_title_right)
    ImageView ivTitleRight;
    @BindView(R.id.et_user_id)
    EditText etUserId;
    @BindView(R.id.btn_commit)
    MainBlueConfirmButton btnCommit;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;
    @BindView(R.id.tv_tips)
    TextView tvTips;
    @BindView(R.id.tv_tips_two)
    TextView tvTipsTwo;

    @Override
    public int getLayout() {
        return R.layout.activity_edit_userid;
    }

    @Override
    public void initPresenter() {
        mPresenter = new EditUserInfoPresenter();
    }

    @Override
    public void initView() {
        btnCommit.setEditText(etUserId, 6);
        etUserId.setText(getIntent().getStringExtra(INTENT_EDIT_USERID));
        if (etUserId.getText().toString().length() >= 6) {
            btnCommit.setBtnEnabled(true);
        }

        tvTips.setText("设置" + getResources().getString(R.string.app_name) + "号");
        tvTipsTwo.setText("用户可通过" + getResources().getString(R.string.app_name) + "号找到你");
        etUserId.setHint("请输入" + getResources().getString(R.string.app_name) + "号");
    }

    @Override
    public void initData() {

        btnCommit.setOnClickListener(view -> {
            UserInfoBean bean = UserInfoUtil.getUserInfo();
            bean.setChatnumber(etUserId.getText().toString());
            mPresenter.editUser(EditUserIdActivity.this, bean);
        });

    }

    /**
     * 修改成功
     */
    @Override
    public void editSuccess() {
        showError("修改成功");
        EventBus.getDefault().post(new EditUserInfoEvent(EditUserInfoEvent.TAG_USERID, etUserId.getText().toString()));
        finish();
    }

    @Override
    public void upLoadResult(UpLoadImgBean data) {

    }

    @Override
    public void editFail() {

    }

    @Override
    public void cityListResult(List<CityListBean> data) {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
